package com.gzbugu.bugusys.util;

/**
 * @author Bokchoy
 * 生成随机字符
 */
public class RandomChars {
	
	public static String randomString(int length) {
	    String retu = "";
	    int d2;
	    char[] letters = initLetters();

	    for (int i = 0; i < length; i++) {
	      d2 = ( (int) (Math.random() * 100) % 52);
	      retu += letters[d2];
	    }
	    return retu;
	}
	
	public static String randomChars(int length) {
		String retu = "";
	    int d2;
	    char[] chars = initChars();

	    for (int i = 0; i < length; i++) {
	      d2 = ( (int) (Math.random() * 100) % chars.length);
	      retu += chars[d2];
	    }
	    return retu;
	}
	
	private static char[] initLetters() {
	    char[] ca = new char[52];
	    for (int i = 0; i < 26; i++) {
	      ca[i] = (char) (65 + i);
	    }
	    for (int i = 26; i < 52; i++) {
	      ca[i] = (char) (71 + i);
	    }
	    return ca;
	}
	
	private static char[] initChars() {
		char[] ca = new char[62];
	    for (int i = 0; i < 26; i++) {
	      ca[i] = (char) (65 + i);
	    }
	    for (int i = 26; i < 52; i++) {
	      ca[i] = (char) (71 + i);
	    }
	    for (int i = 52; i<62; i++) {
	    	ca[i] = (char) (48 + i);
	    }
	    return ca;
	}
}
